/**
 * Created With IntelliJ IDEA
 * Description:leetcode：101. 对称二叉树
 * <a href="https://leetcode.cn/problems/symmetric-tree/">...</a>
 * User: DELL
 * Data: 2023-01-12
 * Time: 22:59
 */

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    public TreeNode(int val) {
        this.val = val;
    }
}
//总体思路就是双指针同步向二叉树的下一层移动比对
public class Solution {
    public boolean isSymmetric(TreeNode root) {
        return check(root,root);
    }

    public boolean check(TreeNode p1,TreeNode p2) {
        if (p1 == null && p2 == null) {
            return true;
        }
        if (p1 == null || p2 == null) {
            return false;
        }
        return p1.val == p2.val && check(p1.left,p2.right) && check(p1.right,p2.left);
    }
}